package com.zonta.finance.admin.controller;


import com.zonta.finance.common.dto.ApiResponse;
import com.zonta.finance.domain.form.CreateSysResourceForm;
import com.zonta.finance.domain.form.DelSysResourceForm;
import com.zonta.finance.domain.form.ListSysResourceForm;
import com.zonta.finance.domain.form.UpdateSysResourceForm;
import com.zonta.finance.domain.vo.GetSysResourceVo;
import com.zonta.finance.domain.vo.ListSysResourceVo;
import com.zonta.finance.serivce.ISysResourceService;
import groovyjarjarantlr4.v4.runtime.misc.NotNull;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 系统资源 前端控制器
 * </p>
 *
 * @author zonta
 * @since 2024-07-25
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/sysResource")
public class SysResourceController {
    private final ISysResourceService sysResourceService;

    @ApiModelProperty(value = "创建资源")
    @PostMapping("/create")
    public ApiResponse<Boolean> create(@Valid @RequestBody CreateSysResourceForm form){
        return ApiResponse.success(sysResourceService.createByFrom(form));
    }

    @ApiOperation(value = "修改资源")
    @PostMapping(value = "/update")
    public ApiResponse<Boolean> update(@Valid @RequestBody UpdateSysResourceForm form) {
        return ApiResponse.success(sysResourceService.UpdateByFrom(form));
    }
    @ApiOperation(value = "查看资源列表")
    @PostMapping(value = "/list")
    public ApiResponse<List<ListSysResourceVo>> list(@Valid @RequestBody ListSysResourceForm form) {
        return ApiResponse.success(sysResourceService.getListByFrom(form));
    }

    @ApiOperation(value = "删除资源")
    @PostMapping(value = "/del")
    public ApiResponse<Boolean> del(@Valid @RequestBody DelSysResourceForm form) {
        return ApiResponse.success(sysResourceService.delByFrom(form));
    }

    @ApiOperation(value = "查询资源明细")
    @GetMapping(value = "get")
    public ApiResponse<GetSysResourceVo> get(@Valid @NotNull @RequestParam("id") Integer id) {
        return ApiResponse.success(sysResourceService.get(id));
    }
}
